cmake_minimum_required(VERSION 2.8.3)
project(rplidar_ros)

set(RPLIDAR_SDK_PATH "./sdk/")
# set(RPLIDAR_INCLUDE_PATH "./include/")
set(CMAKE_BUILD_TYPE "Release")
set(CMAKE_CXX_FLAGS "-std=c++11 ${CMAKE_CXX_FLAGS}")

FILE(GLOB RPLIDAR_SDK_SRC 
  "${RPLIDAR_SDK_PATH}/src/arch/linux/*.cpp"
  "${RPLIDAR_SDK_PATH}/src/dataunpacker/*.cpp"
  "${RPLIDAR_SDK_PATH}/src/dataunpacker/unpacker/*.cpp"
  "${RPLIDAR_SDK_PATH}/src/hal/*.cpp"
  "${RPLIDAR_SDK_PATH}/src/*.cpp"
)
set(OpenCV_DIR /usr/share/OpenCV/)
find_package(catkin REQUIRED COMPONENTS
  roscpp
  rosconsole
  sensor_msgs
  rospy
  std_msgs
  mcq_msgs
  message_filters
  # OpenCV
  # Ceres
)
include_directories(
  ${RPLIDAR_SDK_PATH}/include
  ${RPLIDAR_SDK_PATH}/src
  ${catkin_INCLUDE_DIRS}
)

FIND_PACKAGE( OpenMP REQUIRED)
if(OPENMP_FOUND)
message("OPENMP FOUND")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}")
endif()

catkin_package()

add_executable(rplidarNode src/node.cpp ${RPLIDAR_SDK_SRC})
target_link_libraries(rplidarNode ${catkin_LIBRARIES})

# 查找Ceres库并设置路径
include_directories(${CERES_INCLUDE_DIRS})
include_directories(include)
# 指定源文件
set(SOURCES
"include/DBSCAN.cpp"
"include/Myulits.cpp"
"include/fitting.cpp"
"include/kalman.cpp"
"include/Track.cpp"
)
add_executable(rplidarNodeClient src/client.cpp ${SOURCES} )
set(CERES_LIBRARIES /usr/local/lib/libceres.a
/usr/lib/x86_64-linux-gnu/libglog.a
/usr/lib/x86_64-linux-gnu/libgflags.so
/usr/lib/x86_64-linux-gnu/libunwind.so.8
/usr/lib/x86_64-linux-gnu/libcxsparse.so
/usr/lib/x86_64-linux-gnu/liblapack.so
/usr/lib/x86_64-linux-gnu/libblas.so
/usr/lib/x86_64-linux-gnu/libcholmod.so)

#message(STATUS "**********************"  ${CERES_LIBRARIES})

target_link_libraries(rplidarNodeClient ${catkin_LIBRARIES} ${CERES_LIBRARIES})
add_dependencies(rplidarNodeClient mcq_msgs_generate_messages_cpp)

install(TARGETS rplidarNode rplidarNodeClient
  ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
  LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
  RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
)

install(DIRECTORY launch rviz sdk
  DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}
  USE_SOURCE_PERMISSIONS
)
